﻿using RockBus.Composition.Interfaces;
using System;
using System.Collections.Generic;
using System.Web.Http.Dependencies;

namespace RockBus.Services.WebApi
{
    public class WebApiDependencyResolver : IDependencyResolver
    {
        public IDependencyScope BeginScope()
        {
            return this;
        }

        public object GetService(Type type)
        {
            try
            {
                return DependencyManager.Instance.Resolve(type);
            }
            catch
            {
                return null;
            }
        }

        public IEnumerable<object> GetServices(Type type)
        {
            try
            {
                return DependencyManager.Instance.ResolveAll(type);
            }
            catch
            {
                return new List<object>();
            }
        }

        public void Dispose()
        {
        }
    }
}
